/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 8 -*- */
/*
* gtruritexttag.c
* Copyright (C) Jonas Hagmar 2009 <gnotterdev@gmail.com>
* 
* gtruritexttag.c is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* 
* gtruritexttag.c is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License along
* with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "gtruritexttag.h"

static void gtr_uri_text_tag_dispose (GObject * object);
static void gtr_uri_text_tag_finalize (GObject * object);

G_DEFINE_TYPE (GtrUriTextTag, gtr_uri_text_tag, GTK_TYPE_TEXT_TAG)
     typedef struct _GtrUriTextTagPrivate GtrUriTextTagPrivate;

     struct _GtrUriTextTagPrivate
     {
       gchar *uri;
       gboolean underlined;
       gboolean bold;
     };

#define GTR_URI_TEXT_TAG_GET_PRIVATE(o)  \
   (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTR_TYPE_URI_TEXT_TAG, GtrUriTextTagPrivate))

     static void gtr_uri_text_tag_class_init (GtrUriTextTagClass * klass)
{
  GObjectClass *g_object_class;

  /* Add private structure */
  g_type_class_add_private (klass, sizeof (GtrUriTextTagPrivate));

  /* Get the parent gobject class */
  g_object_class = G_OBJECT_CLASS (klass);

  /* Hook finalization functions */
  g_object_class->dispose = gtr_uri_text_tag_dispose;	/* instance destructor, reverse of init */
  g_object_class->finalize = gtr_uri_text_tag_finalize;	/* class finalization, reverse of class init */


}

static void
gtr_uri_text_tag_init (GtrUriTextTag * uri_text_tag)
{
  /*GValue vt = {0}; */
  /* Retrieve the private data structure */
  GtrUriTextTagPrivate *priv = GTR_URI_TEXT_TAG_GET_PRIVATE (uri_text_tag);

  /* Initialize private fields */
  priv->uri = NULL;
  priv->underlined = FALSE;
  priv->bold = FALSE;

  /*g_value_init (&vt, G_TYPE_STRING);
     g_value_set_static_string (&vt, "blue");
     g_object_set_property (G_OBJECT (uri_text_tag), "foreground", &vt);
     g_value_unset (&vt); */

}

GtrUriTextTag *
gtr_uri_text_tag_new (void)
{
  return g_object_new (GTR_TYPE_URI_TEXT_TAG, NULL);
}

static void
gtr_uri_text_tag_dispose (GObject * object)
{

  GtrUriTextTag *self = GTR_URI_TEXT_TAG (object);
  GtrUriTextTagPrivate *priv;

  priv = GTR_URI_TEXT_TAG_GET_PRIVATE (self);

  if (priv->uri)
    {
      g_free (priv->uri);
      priv->uri = NULL;
    }

  G_OBJECT_CLASS (gtr_uri_text_tag_parent_class)->dispose (object);

}

static void
gtr_uri_text_tag_finalize (GObject * object)
{
  G_OBJECT_CLASS (gtr_uri_text_tag_parent_class)->finalize (object);
}

void
gtr_uri_text_tag_set_uri (GtrUriTextTag * tag, gchar const *uri)
{
  GtrUriTextTagPrivate *priv;
  priv = GTR_URI_TEXT_TAG_GET_PRIVATE (tag);

  if (priv->uri)
    {
      g_free (priv->uri);
      priv->uri = NULL;
    }
  if (uri)
    {
      priv->uri = g_strdup (uri);
    }
}

gchar const *
gtr_uri_text_tag_get_uri (GtrUriTextTag * tag)
{
  GtrUriTextTagPrivate *priv;
  priv = GTR_URI_TEXT_TAG_GET_PRIVATE (tag);

  return priv->uri;
}

void
gtr_uri_text_tag_set_underlined (GtrUriTextTag * tag, gboolean underlined)
{
  GtrUriTextTagPrivate *priv = GTR_URI_TEXT_TAG_GET_PRIVATE (tag);
  GValue vt = { 0 };

  g_value_init (&vt, PANGO_TYPE_UNDERLINE);
  if (underlined)
    g_value_set_enum (&vt, PANGO_UNDERLINE_SINGLE);
  else
    g_value_set_enum (&vt, PANGO_UNDERLINE_NONE);

  g_object_set_property (G_OBJECT (tag), "underline", &vt);

  g_value_unset (&vt);

  priv->underlined = underlined;
}

gboolean
gtr_uri_text_tag_get_underlined (GtrUriTextTag * tag)
{
  GtrUriTextTagPrivate *priv;
  priv = GTR_URI_TEXT_TAG_GET_PRIVATE (tag);

  return priv->underlined;
}

void
gtr_uri_text_tag_set_color (GtrUriTextTag * tag, gchar const *color)
{
  GValue vt = { 0 };

  g_value_init (&vt, G_TYPE_STRING);
  g_value_set_string (&vt, color);
  g_object_set_property (G_OBJECT (tag), "foreground", &vt);
  g_value_unset (&vt);
}

void
gtr_uri_text_tag_set_bold (GtrUriTextTag * tag, gboolean bold)
{
  GtrUriTextTagPrivate *priv = GTR_URI_TEXT_TAG_GET_PRIVATE (tag);
  GValue vt = { 0 };

  g_value_init (&vt, G_TYPE_INT);
  if (bold)
    g_value_set_int (&vt, PANGO_WEIGHT_BOLD);
  else
    g_value_set_int (&vt, PANGO_WEIGHT_NORMAL);

  g_object_set_property (G_OBJECT (tag), "weight", &vt);

  g_value_unset (&vt);

  priv->bold = bold;
}

gboolean
gtr_uri_text_tag_get_bold (GtrUriTextTag * tag)
{
  GtrUriTextTagPrivate *priv;
  priv = GTR_URI_TEXT_TAG_GET_PRIVATE (tag);

  return priv->bold;
}

#define __GTR_URI_TEXT_TAG_C__
